import { TOKEN_KEY } from '@/enums/cacheEnum';
import { simpleSessionStorage, simpleLocalStorage } from './session'

// local or session
const isLocal = true

export function getToken() {
  return simpleLocalStorage.getItem(TOKEN_KEY);
}

export function getAuthCache<T>(key: string) {
  const fn = isLocal ? simpleLocalStorage : simpleSessionStorage;
  return fn.getItem(key) as T;
}

export function setAuthCache(key: string, value: any, expire=null ) {
  const fn = isLocal ? simpleLocalStorage : simpleSessionStorage;
  return fn.setItem(key, value, expire);
}

export function clearAuthCache(key: string, immediate = true) {
  const fn = isLocal ? simpleLocalStorage : simpleSessionStorage;
  return immediate ? fn.removeAll() : fn.removeItem(key)
}
